package com.hjs.servlet.regularinspection.pavementflatness;

import com.hjs.bean.PavementFlatnessView;
import com.hjs.mapper.ViewMapper;
import com.hjs.tools.Mapper;
import com.hjs.tools.RequestUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/PavementFlatness/search")
@Slf4j
public class SearchPavementFlatness extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) {
        /*
         * 提供参数
         * flatnessID
         */
        RequestUtil requestUtil = new RequestUtil(request, response);
        try (SqlSession sqlSession = Mapper.getSqlSession()) {
            ViewMapper viewMapper = sqlSession.getMapper(ViewMapper.class);
            PavementFlatnessView flatnessView = viewMapper.getOnePavementFlatnessViewById(requestUtil.getInt("flatnessID"));
            requestUtil.responseWrite(Mapper.toJsonString(flatnessView));
        } catch (Exception e) {
            log.error(e.toString());
            requestUtil.responseFail("未知错误");
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) {
        doPost(request,response);
    }
}
